<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
  
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
    <vxe-table :data="list" :loading="loading" @selection-change="handleSelectionChange">
      <vxe-table-column label="编号" width="100">
        <template #default="{ row }">
          <el-button link type="primary" @click="handleApprove(row.apply.number)">{{ row.apply.number }}</el-button>
        </template>
      </vxe-table-column>
      <vxe-table-column label="数量" prop="num"></vxe-table-column>
      <vxe-table-column label="申请人" prop="createUserName"></vxe-table-column>
      <vxe-table-column label="备注" prop="remark"></vxe-table-column>
    </vxe-table>
  <div class="pagination-container ">
    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="paging.pageNum"
      :limit.sync="paging.pageSize"
      @pagination="onPageChange"
    />
  </div>
    <approve ref="approve" @sub="onSub"></approve>
  </div>
</template>
 
  
  <script>
  import api from "./api.js";
  import { getCurrentInstance} from 'vue'
  import Approve from './approve.vue'
  
  export default {
    name: "AssetInApply",
    components: {
      Approve: Approve
    },
    data() {
      return {
        // 遮罩层
        loading: true,
        // 导出遮罩层
        exportLoading: false,
        // 选中数组
        ids: [],
        // 非单个禁用
        single: true,
        // 非多个禁用
        multiple: true,
        // 显示搜索条件
        showSearch: true,
        // 总条数
        total: 0,
        // 【请填写功能名称】表格数据
        list: [],
        // 弹出层标题
        title: "",
        // 是否显示弹出层
        open: false,
        paging: {
          pageNum: 1,
          pageSize: 10,
        },
        // 查询参数
        queryParams: {
          configName: null,
          configDesc: null,
          configType: null,
          orderType: null,
          status: null,
          createUserId: null,
          updateUserId: null
        },
        // 表单参数
        form: {},
      };
    },
    created() {
      this.getList();
    },
    setup() {
      const { proxy } = getCurrentInstance();
      const { apply_state } = proxy.useDict("apply_state");
      return {
        apply_state
      }
    },
    methods: {
      /** 查询【请填写功能名称】列表 */
      getList() {
        this.loading = true;
        const {pageNum, pageSize} = this.paging;

        const query = {...this.queryParams};
        const pageReq = {page: pageNum - 1, size: pageSize};
        api.list(query, pageReq).then(response => {
          const { content, totalElements } = response
          this.list = content;
          this.total = totalElements;
          this.loading = false;
        });
      },
      onPageChange({page, limit}) {

        this.paging.pageNum = page;
        this.paging.pageSize = limit;
        this.getList();
      },
      // 取消按钮
      cancel() {
        this.open = false;
        this.reset();
      },
      // 表单重置
      reset() {
        this.form = {
          id: null,
          configName: null,
          configDesc: null,
          configType: null,
          orderType: null,
          status: 0,
          createTime: null,
          updateTime: null,
          createUserId: null,
          updateUserId: null
        };
        this.resetForm("form");
      },
      /** 搜索按钮操作 */
      handleQuery() {
        this.queryParams.pageNum = 1;
        this.getList();
      },
      /** 重置按钮操作 */
      resetQuery() {
        this.resetForm("queryForm");
        this.handleQuery();
      },
      // 多选框选中数据
      handleSelectionChange(selection) {
        this.ids = selection.map(item => item.id)
        this.single = selection.length!==1
        this.multiple = !selection.length
      },
      /** 修改按钮操作 */
      handleApprove(row) {
        this.$refs.approve.open(row);
      },
      onSub() {
        this.getList();
      }
    }
  };
  </script>
  <style lang="scss" scoped>
  .app-container {
    display: flex;
    flex-direction: column;
    height: 92vh; 
    overflow: hidden; 
  }
  
  .vxe-table {
    flex: 1;
    overflow: auto;
  }
  
  .pagination-container {
    display: flex;
    justify-content: flex-end; 
  
  }
  </style>
  
  